package com.dopdxd.combase.base

import android.os.Bundle
import android.view.LayoutInflater
import androidx.appcompat.app.AppCompatActivity
import androidx.viewbinding.ViewBinding
import com.gyf.immersionbar.ImmersionBar
import com.lwz.common.R
import com.lwz.common.utils.ActivityCollector

/**
 * @Description: Activity基类
 * @Author: kim
 * @CreateDate: 2024/4/8 10:28
 * @Version: 1.0
 */
abstract class BaseActivity <VB : ViewBinding>(private val inflate: (LayoutInflater) -> VB) : AppCompatActivity(){

    lateinit var mBinding: VB

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        ActivityCollector.addActivity(this)
        mBinding = inflate(layoutInflater)
        setContentView(mBinding.root)
        if (isImmersion()) {
            ImmersionBar.with(this).statusBarDarkFont(true).init()
        } else {
            ImmersionBar.with(this).statusBarDarkFont(true).statusBarColor(statusBarColor())
                .fitsSystemWindows(true).init()
        }
        initView(savedInstanceState)
        initListener()
        subscribeData()
        loadData()
    }

    protected open fun isImmersion():Boolean {
        return false
    }

    protected open fun statusBarColor():Int {
        return R.color.white
    }


    protected open fun initView(savedInstanceState: Bundle?){}

    protected open fun initListener() {}

    protected open fun subscribeData() {}

    protected open fun loadData() {}

    override fun onDestroy() {
        super.onDestroy()
        ActivityCollector.removeActivity(this)
    }

}